﻿/****************
* Authored by Zhuo "Wizcas" Chen
* 2018 © Wubi.fun all rights reserved
*****************/

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class ResBar : MonoBehaviour 
{
    [SerializeField] ResItem[] items;

    private void Awake()
    {
        ResManager.instance.onStorageUpdated += UpdateResList;
        Hide();
    }

    void UpdateResList(IEnumerable<Res> reslist)
    {
        foreach(var res in reslist) { UpdateRes(res); }
    }

    void UpdateRes(Res res)
    {
        var item = items.FirstOrDefault(it => it.id == res.id);
        if (item == null) return;
        item.Refresh(res);
    }

    public void Show() { gameObject.SetActive(true); }
    public void Hide() { gameObject.SetActive(false); }
}
